package com.zac.basicAOP;

import java.lang.reflect.Method;

import org.springframework.aop.MethodBeforeAdvice;

public class ExcuteMain {

	public static void main(String[] args) {
		UserDao userDao = new UserDao();
		UserServiceImpl target = new UserServiceImpl();
		target.setUserDao(userDao);
		//Initiate the log aspect
		MethodBeforeAdvice log = new MethodBeforeAdvice() {
			
			@Override
			public void before(Method m, Object[] param, Object target)
					throws Throwable {
				// TODO Auto-generated method stub
				System.out.println("call method: " + m.getName());
				
			}
		};
		//Dynamic proxy class
		UserService userService = (UserService) AopProxyFactory.creatProxy(target, log);
		userService.create("aop", "mypassword");
		userService.login("aop", "mypassword");
		//check the data persisted
		userDao.print();
	}
	
}
